package org.guoyuliang.iching;

import java.util.List;
import java.util.Map;

public class GuaForNum {

    public static void main(String[] args) {
        int num1=999;
        int num2= 600;
        int num3= 002;
        List<Gua> guaList = Gua.initGuaList();
        List<Gua> xianTianGuaList = Gua.initXianTianGuaList();
        Map<String, Gua> mapGua = MapUtils.cteateIndexMap(guaList, Gua::createIndex);
        Map<String, Gua> mapXianTianGua = MapUtils.cteateIndexMap(xianTianGuaList, Gua::createIndex);
        Gua xiaGua = getXianTianByNUm(num1, xianTianGuaList);
        Gua shangGua = getXianTianByNUm(num2, xianTianGuaList);
        int yaoNum=getYaoNum(num3);
        String index=xiaGua.createIndex()+shangGua.createIndex();
        String name = mapGua.get(index).getName();
        System.out.println("下卦："+xiaGua.getName());
        System.out.println("上卦："+shangGua.getName());
        System.out.println( "结果："+name+"卦:"+yaoNum+"爻" );

    }

    private static int getYaoNum(int num3) {
        int yaoNum= num3 % 6;
        if(yaoNum==0){
            yaoNum=6;
        }
        return yaoNum;
    }

    private static Gua getXianTianByNUm(int num1, List<Gua> xianTianGuaList) {
        int i = num1%8;
        if(i==0){
            i=8;
        }
        return xianTianGuaList.get(i-1);
    }

}
